<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
	version="1.0"
	xmlns:htm="http://www.w3.org/1999/xhtml"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output
		method="html" />

	<!-- $Revision: 99 $ $Date: 2010-12-31 15:22:03 +0000 (Fri, 31 Dec 2010) $ -->
	
	<xsl:template
		match="character-sheet-traveller">
		<html>
			<head>
				<title>Traveller Character Sheet for
					<xsl:value-of
						select="personal/name" />
				</title>
				<style type="text/css">
					body {
					    font-family: Arial;
					    font-size: 14pt;
					    color: red;
					    background: black;
					    padding: 10px;
					}
					hr {
					    color:red;
					}
					table {
					    border-color: red;
					    border-width: thin;
					    border-style: solid;
					}
					tr.o {
					    background: red;
					    color: black;
					}
					td {
					    border-color: red;
					    border-width: thin;
					    border-style: solid
					}
					td.r {
					    text-align: right;
					    border-color: red;
					    border-width: thin;
					    border-style: solid
					}
					th {
					    border-color: red;
					    border-width: thin;
					    border-style: solid
					}</style>
			</head>
			<body>
				<h1>Traveller Character Sheet for <xsl:value-of
						select="personal/name" /></h1>

				<xsl:call-template
					name="personal" />
				<xsl:call-template
					name="characteristics" />
				<xsl:call-template
					name="skills" />
				<xsl:call-template
					name="psionic-talents" />
				<xsl:call-template
					name="aspects" />
				<xsl:call-template
					name="weapons" />
				<xsl:call-template
					name="equipment" />
				<xsl:call-template
					name="finances" />
				<xsl:call-template 
					name="general" />
				<xsl:call-template
					name="characteristic-mods" />
				<hr />
				<code>
					Template: $Revision: 99 $ $Date: 2010-12-31 15:22:03 +0000 (Fri, 31 Dec 2010) $
				</code>
			</body>
		</html>
	</xsl:template>

	<!-- Personal Info -->

	<xsl:template
		name="personal">
		<h2>Personal Information</h2>
		<table>
			<tr
				class="o">
				<th>Item</th>
				<th>Value</th>
			</tr>
			<xsl:for-each
				select="personal/child::*">
				<tr>
					<td>
						<xsl:value-of
							select="name()" />
					</td>
					<td>
						<xsl:value-of
							select="." />
					</td>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>

	<!-- Characteristics -->

	<xsl:template
		name="characteristics">

		<h2>Characteristics</h2>
		<table>
			<tr
				class="o">
				<th>Characteristic</th>
				<th>Value</th>
				<th>Current</th>
				<th>Modifier</th>
			</tr>
			<tr>
				<td>Strength (STR)</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/str" />
				</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/strcur" />
				</td>
				<td>
					<xsl:call-template
						name="modifier-calc">
						<xsl:with-param
							name="input"
							select="characteristics/strcur" />
					</xsl:call-template>
				</td>
			</tr>
			<tr>
				<td>Dexterity (DEX)</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/dex" />
				</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/dexcur" />
				</td>
				<td>
					<xsl:call-template
						name="modifier-calc">
						<xsl:with-param
							name="input"
							select="characteristics/dexcur" />
					</xsl:call-template>
				</td>
			</tr>
			<tr>
				<td>Endurance (END)</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/end" />
				</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/endcur" />
				</td>
				<td>
					<xsl:call-template
						name="modifier-calc">
						<xsl:with-param
							name="input"
							select="characteristics/endcur" />
					</xsl:call-template>
				</td>
			</tr>
			<tr>
				<td>Intelligence (INT)</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/int" />
				</td>
				<td>&#160;</td>
				<td>
					<xsl:call-template
						name="modifier-calc">
						<xsl:with-param
							name="input"
							select="characteristics/int" />
					</xsl:call-template>
				</td>
			</tr>
			<tr>
				<td>Education (EDU)</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/edu" />
				</td>
				<td>&#160;</td>
				<td>
					<xsl:call-template
						name="modifier-calc">
						<xsl:with-param
							name="input"
							select="characteristics/edu" />
					</xsl:call-template>
				</td>
			</tr>
			<tr>
				<td>Social Standing (SOC)</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/soc" />
				</td>
				<td>&#160;</td>
				<td>
					<xsl:call-template
						name="modifier-calc">
						<xsl:with-param
							name="input"
							select="characteristics/soc" />
					</xsl:call-template>
				</td>
			</tr>
			<tr>
				<td>Psionic Strength (PSI)</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/psi" />
				</td>
				<td
					class="r">
					<xsl:value-of
						select="characteristics/psicur" />
				</td>
				<td>
					<xsl:call-template
						name="modifier-calc">
						<xsl:with-param
							name="input"
							select="characteristics/psicur" />
					</xsl:call-template>
				</td>
			</tr>
		</table>
	</xsl:template>

	<!-- Aspects -->

	<xsl:template
		name="aspects">
		<h2>Aspects</h2>
		<table>
			<tr
				class="o">
				<th>Aspect Description</th>
			</tr>
			<xsl:for-each
				select="aspects/aspect">
				<tr>
					<td>
						<xsl:value-of
							select="aspect-desc" />
					</td>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>

	<!-- Skills -->

	<xsl:template
		name="skills">
		<h2>Skills</h2>
		<table>
			<tr
				class="o">
				<th>Skill</th>
				<th>Level</th>
			</tr>
			<xsl:for-each
				select="skills/skill">
				<tr>
					<td>
						<xsl:value-of
							select="skill-name" />
					</td>
					<td
						class="r">
						<xsl:value-of
							select="skill-level" />
					</td>
				</tr>
			</xsl:for-each>

		</table>
	</xsl:template>

	<!-- Psionic Talents -->

	<xsl:template
		name="psionic-talents">
		<h2>Psionic Talents</h2>
		<table>
			<tr
				class="o">
				<th>Psionic Talent</th>
				<th>Level</th>
			</tr>
			<xsl:for-each
				select="psionic-talents/talent">
				<tr>
					<td>
						<xsl:value-of
							select="talent-name" />
					</td>
					<td
						class="r">
						<xsl:value-of
							select="talent-level" />
					</td>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>

	<!-- Weapons -->

	<xsl:template
		name="weapons">
		<h2>Weapons</h2>
		<table>
			<tr
				class="o">
				<th>Weapon</th>
				<th>Skill</th>
				<th>Range</th>
				<th>Damage</th>
				<th>Auto</th>
				<th>Heft/Recoil</th>
			</tr>
			<xsl:for-each
				select="weapons/weapon">
				<tr>
					<td>
						<xsl:value-of
							select="weapon-name" />
					</td>
					<td
						class="r">
						<xsl:value-of
							select="weapon-skill" />
					</td>
					<td
						class="r">
						<xsl:value-of
							select="weapon-range" />
					</td>
					<td
						class="r">
						<xsl:value-of
							select="weapon-damage" />
					</td>
					<td
						class="r">
						<xsl:value-of
							select="auto" />
					</td>
					<td
						class="r">
						<xsl:value-of
							select="heft-recoil" />
					</td>
				</tr>
			</xsl:for-each>

		</table>
	</xsl:template>

	<!-- Equipment -->

	<xsl:template
		name="equipment">
		<h2>Equipment</h2>
		<table>
			<tr
				class="o">
				<th>Item</th>
				<th>Weight</th>
			</tr>
			<xsl:for-each
				select="equipment/item">
				<tr>
					<td>
						<xsl:value-of
							select="item-name" />
					</td>
					<td
						class="r">
						<xsl:value-of
							select="item-weight" />
					</td>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>

	<!-- Finances -->

	<xsl:template
		name="finances">
		<h2>Finances</h2>
		<table>
			<tr
				class="o">
				<th>Item</th>
				<th>Amount</th>
			</tr>
			<tr>
				<td>
					Cash
				</td>
				<td
					class="r">
					<xsl:value-of
						select="finances/cash" />
				</td>
			</tr>
			<tr>
				<td>
					Assets
				</td>
				<td
					class="r">
					<xsl:value-of
						select="finances/assets" />
				</td>
			</tr>
			<tr>
				<td>
					Debts
				</td>
				<td
					class="r">
					<xsl:value-of
						select="finances/debts" />
				</td>
			</tr>
			<tr>
				<td>
					Monthly Expenses
				</td>
				<td
					class="r">
					<xsl:value-of
						select="finances/monthly-expense" />
				</td>
			</tr>
			<tr>
				<td>
					Monthly Income
				</td>
				<td
					class="r">
					<xsl:value-of
						select="finances/monthly-income" />
				</td>
			</tr>
		</table>
	</xsl:template>
	
	<!-- General Items -->
	
	<xsl:template
		name="general">
		<h2>General Items</h2>
		<table>
			<tr
				class="o">
				<th>Name</th>
				<th>Value</th>
			</tr>
			<xsl:for-each
				select="general/general-item">
				<tr>
					<td>
						<xsl:value-of
							select="general-name" />
					</td>
					<td
						class="r">
						<xsl:value-of
							select="general-value" />
					</td>
				</tr>
			</xsl:for-each>
			
		</table>
	</xsl:template>
	

	<!-- Display score vs. modifier table -->

	<xsl:template
		name="characteristic-mods">
		<h2>Characteristic Score vs. Modifier</h2>
		<table>
			<tr
				class="o">
				<th>Score</th>
				<th>Modifier</th>
			</tr>
			<xsl:call-template
				name="for-loop">
				<xsl:with-param
					name="i">0</xsl:with-param>
				<xsl:with-param
					name="count">15</xsl:with-param>
			</xsl:call-template>
		</table>
	</xsl:template>

	<!-- Generate modifier from characteristic -->

	<xsl:template
		name="modifier-calc">
		<xsl:param
			name="input" />
		<xsl:value-of
			select="floor($input div 3 - 2)" />
	</xsl:template>

	<!-- Simulate a for-loop -->

	<xsl:template
		name="for-loop">

		<xsl:param
			name="i" />
		<xsl:param
			name="count" />

		<xsl:choose>
			<xsl:when
				test="$i mod 2 = 1">
				<tr
					class="o">
					<td
						class="r">
						<xsl:value-of
							select="$i" />
					</td>
					<td
						class="r">
						<xsl:call-template
							name="modifier-calc">
							<xsl:with-param
								name="input"
								select="$i" />
						</xsl:call-template>
					</td>
				</tr>

			</xsl:when>
			<xsl:otherwise>
				<tr>
					<td
						class="r">
						<xsl:value-of
							select="$i" />
					</td>
					<td
						class="r">
						<xsl:call-template
							name="modifier-calc">
							<xsl:with-param
								name="input"
								select="$i" />
						</xsl:call-template>
					</td>
				</tr>
			</xsl:otherwise>
		</xsl:choose>

		<xsl:if
			test="$i &lt;= $count">
			<xsl:call-template
				name="for-loop">
				<xsl:with-param
					name="i">
					<xsl:value-of
						select="$i + 1" />
				</xsl:with-param>
				<xsl:with-param
					name="count">
					<xsl:value-of
						select="$count" />
				</xsl:with-param>
			</xsl:call-template>
		</xsl:if>

	</xsl:template>

</xsl:stylesheet>
